<include file="Public/head" />
<link rel="stylesheet" href="/static/kindeditor/themes/default/default.css" />
<link rel="stylesheet" href="/static/kindeditor/plugins/code/prettify.css" />
<script charset="utf-8" src="/static/kindeditor/kindeditor.js"></script>
<script charset="utf-8" src="/static/kindeditor/lang/zh_CN.js"></script>
<script charset="utf-8" src="/static/kindeditor/plugins/code/prettify.js"></script>
<script>
	var editor;
	KindEditor.ready(function(K) {
		editor = K.create('textarea[name="content1"]', {
			cssPath : '/static/kindeditor/plugins/code/prettify.css',
			uploadJson : '/Article/ueditor',
			allowFileManager : false,
			height:'800px'
		});
		prettyPrint();
	});
</script>
</head>
<include file="Public/common_header" />
<div class="mian">
    <include file="Public/sidebar"  menu="clcwht.nrrbfb" />

    <div class="mianR">
        <h3 class="yonghu">牛人日报-<if condition="$article">编辑<else/>新建</if></h3>
		<div class="newly-build">
			<ul>
				<li><span>标题</span><input type="text" value="{$article.article_title}" id="article_title" class="build-title" /></li>
				<li><span>牛人</span>
					<select id="author">
						<option value="">请选择牛人</option>
						<volist name="author" id="vo">
						<option value="{$vo.user_id}" <if condition="$vo['user_id'] eq $article['user_id']">selected="selected"</if>><if condition="$vo['nick_name']">{$vo.nick_name}<else/>{$vo.mobile}</if></option>
						</volist>
					</select>
				</li>
				<li><span>类型</span>
					<select id="attribute">
						<option value="0">请选择类型</option>
						<option <if condition="$article['article_attribute'] eq 1">selected="selected"</if> value="1">图文</option>
						<option <if condition="$article['article_attribute'] eq 2">selected="selected"</if> value="2">视频</option>
					</select>
				</li>
				<li><span>是否推荐</span>
					<select id="top">
						<option value="">请选择是否推荐</option>
						<option value="1" <if condition="$article.is_top eq 1">selected="selected"</if>>是</option>
						<option value="0" <if condition="$article.is_top eq 0">selected="selected"</if>>否</option>
					</select>
				</li>
				<input type="hidden" id="article_focus" value="{$article.article_focus}" />
				<li class="build-file"><span>焦点图</span><input type="file" /><div class="build-map" id="focus_box"><if condition="$article['article_focus']"><img src="{$t|get_content_cdnurl}{$article.article_focus}" /><else/>+</if></div>
                <script type='text/javascript'>
                    new IFrameUploadImg(
                    '浏览'
                    , 'http://' + window.location.host + '/Article/uploadPic'
                    , function (res) {
                    	var cdn_url = '{$t|get_content_cdnurl}';
                        if (res.code == 200) {
                            var head_url = res.data[0];
                            $('#focus_box').html('<img src="'+cdn_url + head_url+'" />');
                            $("#article_focus").val(head_url);
                        }
                    });
                </script>
				</li>
				<input type="hidden" id="article_thumb" value="{$article.article_thumb}" />
				<li class="build-file"><span>缩略图</span><input type="file"><div class="build-map" id="thumb_box"><if condition="$article['article_thumb']"><img src="{$t|get_content_cdnurl}{$article.article_thumb}" /><else/>+</if></div>
				<script type='text/javascript'>
					new IFrameUploadImg(
                    '浏览'
                    , 'http://' + window.location.host + '/Article/uploadPic'
                    , function (res) {
                    	var cdn_url = '{$t|get_content_cdnurl}';
                        if (res.code == 200) {
                            var head_url = res.data[0];
                            $('#thumb_box').html('<img src="'+cdn_url + head_url+'" />');
                            $("#article_thumb").val(head_url);
                        }
                    });
                </script>
				</li>
				<li>
					<span>发布时间</span>
					<input type="text" class="build-title" id="publish_time" name="publish_time" value="<if condition="!empty($article['cron_time']) && $article['status'] == 3">{$article.cron_time|date="Y-m-d H:i:s", ###}</if>" readonly="" placeholder="发布时间">
				</li>
				<li>
					<span>日报简介</span>
					<textarea id="desc" style="width:300px;height:100px">{$article.article_desc}</textarea>
				</li>
				<li>
					<span>内容</span>
					<textarea id="content" name="content1">{$article.article_content}</textarea>
				</li>		
			</ul>
		</div>
		<div class="yongBtn">
            		<input onclick="saveArticle({$article.article_id});" type="button" value="保存" class="queding">	
            		<input type="button" onclick="history.go(-1);" value="取消" class="queding">	
		</div>
		<div class="build-alert">
			<h3>确认页面</h3>
			<a href="#">预览web</a>
			<a href="#">预览APP</a>
			<a href="#">直接发布</a>
		</div>
    </div>
    <div class="clear"></div>
    <include file="Public/foot" />
<script>
	$(function(){
		$("#publish_time").ymdateplugin({
			showTimePanel: true,
			changeMonth: true,
			changeYear: true,
			gotoCurrent: true,
			minDate: "{$date}"
		});
	});

function btn_alert(msg,delay){
	var html='<div class="chenggong"><div class="yunGou"></div><span>'+msg+'</span></div>'
	$(document.body).append(html);
	if(typeof(delay)=="undefined"){
		delay=2000;
		$(".chenggong").fadeIn().delay(delay).fadeOut(0,function(){html.remove();});
	}
}

isSubmit = 1;

function saveArticle(id){
	editor.sync();
	var title = $('#article_title').val();
    title = title.replace(/<\/?[^>]*>/g,'');
    title = title.replace(/[ | ]*\n/g,'');
    title = title.replace(/\n[\s| | ]*\r/g,'');
    title = title.replace(/ /g,'');
	if(!title){
		alert('请填写标题');
		return false;
	}
	var author = $('#author').val();
	if(!author){
		alert('请选择牛人');
		return false;
	}
	var attribute = $('#attribute').val();
	if(attribute <= 0){
		alert('请选择文章类型');
		return false;
	}
	var top = $('#top').val();
	var focus = $('#article_focus').val();
	if(!focus){
		alert('请上传焦点图');
		return false;
	}
	var thumb = $('#article_thumb').val();
	if(!thumb){
		alert('请上传缩略图');
		return false;
	}
	var desc = $('#desc').val();
	var desc1 = desc.replace(/<\/?[^>]*>/g,'');
    desc1 = desc1.replace(/[ | ]*\n/g,'');
    desc1 = desc1.replace(/\n[\s| | ]*\r/g,'');
    desc1 = desc1.replace(/ /g,'');
	if(!desc1){
		alert('请填写日报简介');
		return false;
	}
	var publish_time = $('#publish_time').val();
	var content = $('#content').val();
	var content1 = content.replace(/<\/?[^>]*>/g,'');
    content1 = content1.replace(/[ | ]*\n/g,'');
    content1 = content1.replace(/\n[\s| | ]*\r/g,'');
    content1 = content1.replace(/ /g,'');
	if(!content1){
		alert('请填写内容');
		return false;
	}

	if(isSubmit != 1){
		return false;
	}

	$.post('/Article/saveExpert', {id:id,title:title, author:author,attribute:attribute,top:top, focus:focus, thumb:thumb, desc:desc, content:content, publish_time:publish_time}, function(data){
		isSubmit = 0;
		if(data.code == '200'){
			isSubmit = 1;
			window.location = '/Article/expert';
		}else{
			isSubmit = 1;
			btn_alert(data.msg);
		}
	},'json');

}
</script>
    
    